<?php

$params = require(__DIR__ . '/params.php');
$db = require(__DIR__ . '/db.php');

$config = [
    'id' => 'basic',
    'basePath'     => APP_PATH . DS . 'app',
    'vendorPath'   => APP_PATH . DS . 'vendor',
    'runtimePath'  => APP_PATH . DS . 'runtime',
    'controllerNamespace' => 'app\controllers', //控制器默认命名空间
    'defaultRoute' => 'backend/index/index',   //默认路由
    'language' => 'zh-CN',  //目标语言
    'bootstrap' => ['log','backend'],
    'modules'      => [
        'backend'    => [
            'class' => 'app\modules\backend\backendModule',
        ],
        'api'      => [
            'class' => 'app\modules\api\apiModule',
        ],
        'debug'    => [
            'class' => 'yii\debug\Module',
        ],
        'gii'      => [
            'class'      => 'yii\gii\Module',
            'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.109.128'], // 按需调整这里
        ],
    ],
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'O1IrwZWpINveM_hS4HVwdEdhcfl_Ty2s',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        //身份认证类
        'user' => [
            'class' => 'yii\web\User',
            'identityClass' => 'app\models\Admin',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-app', 'httpOnly' => true],
            'loginUrl' => ['backend/index/login'], //配置登录url
        ],
        'session' => [
            'class' => 'yii\web\CacheSession',
        ],
        //Rbac权限控制
        'authManager' => [
            'class' => 'yii\rbac\DbManager',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,//开启URL美化 
            'showScriptName'=>false,
             //'suffix'=>'.html',
            'rules'=>array(
                 //'<controller:\w+>/<id:\d+>’=>’<controller>/view',
                 //'<controller:\w+>/<action:\w+>/<id:\d+>’=>’<controller>/<action>',
                 //'<controller:\w+>/<action:\w+>’=>’<controller>/<action>',
                //"<controller:\w+>/<action:\w+>"=>"backend/<controller>/<action>",
             )
        ],
        'errorHandler' => [
            'errorAction' => 'backend/index/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => $db,
        /**
         * 语言包配置
         * 将"源语言"翻译成"目标语言". 注意"源语言"默认配置为 'sourceLanguage' => 'en-US'
         * 使用: \Yii::t('common', 'title'); 将common/messages下的common.php中的title转为对应的中文
         */
        'i18n' => [
            'translations' => [
                '*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@app/messages',
                    //'sourceLanguage' => 'en-US',
                    'fileMap' => [
                        'common' => 'common.php',
                        'frontend' => 'frontend.php',
                        'backend' => 'backend.php',
                    ],
                ],
            ],
        ],
    ],
    'params' => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];
}

return $config;
